<template>
  <div class="van">
    <Mysearch @searchfunp="searchfunp" />
    <Mybutton @parentopen="parentopen" />
    <Mytable @updateopen="updateopen" :arr="wxarr" @resetwx="initGetHome" />
    <Mypage
      :pageSize="pageSize"
      :page="page"
      :pageSizes="pageSizes"
      :total="total"
      @changepage="changepage"
      @changepagesize="changepagesize"
    />
    <Dialog
      :btntype="btntype"
      :row="row"
      @parentinti="initGetHome"
      v-if="show"
      @parentclose="parentclose"
    />
  </div>
</template>

<script>
import Mysearch from "./components/Mysearch.vue";
import Mytable from "./components/Mytable.vue";
import Mybutton from "./components/Mybutton.vue";
import Mypage from "./components/Mypage.vue";
import Dialog from "./components/Dialog.vue";
import { getwxApi } from "../../api/wxapi/wxApi";
export default {
  components: {
    Mysearch,
    Mytable,
    Mybutton,
    Mypage,
    Dialog,
  },
  data() {
    return {
      btntype: 0, //0添加 1修改
      row: {},
      show: false,
      wxarr: [], //保存我们的表格数据
      keyword: "",
      keyword1: "",
      page: 1, //page 当前页码
      pageSize: 20, //每一页多少条数据
      total: 100, //总条数
      pageSizes: [20, 40, 60, 80, 100],
    };
  },
  mounted() {
    this.initGetHome();
  },
  beforeDestroy() {
    this.total = this.wxarr.length
  },
  methods: {
    changepagesize(val) {
      this.pageSize = val;
      this.initGetHome();
    },
    changepage(val) {
      this.page = val;
      this.initGetHome();
    },
    
    updateopen(row) {
      //编辑的第一步
      this.row = row;
      this.show = true;
      this.btntype = 1;
    },
    parentclose() {
      this.show = false;
    },
    parentopen() {
      //添加的第一步
      this.show = true;
      this.row = {};
      this.btntype = 0;
    },
    searchfunp(val) {
      this.keyword = val.search1;
      this.keyword1 = val.search2;
      // console.log(this.keyword)
      this.initGetHome();
    },
    initGetHome() {
      getwxApi({
        keyword: this.keyword,
        keyword1: this.keyword1,
        page: this.page,
        pageSize: this.pageSize,
      }).then((res) => {
        // console.log("res",res);
        if (res.code == 200) {
          this.wxarr = res.data;
        }
      });
    },
  },
};
</script>

<style>
.van {
  font-size: 16px;
}
</style>